package com.xdf.testkafk.controller;

import com.alibaba.fastjson.JSON;
import com.xdf.testkafk.rocket.RocketMQProducer;
import com.xdf.testkafk.vo.KafkaMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;

/**
 * @author chanchaw
 * @create 2025-11-01 10:09
 */
@CrossOrigin
@RestController
@RequestMapping("/rocket")
@RequiredArgsConstructor
@Slf4j
public class RocketController {
    private final RocketMQProducer producer;

    private static final KafkaMessage message = new KafkaMessage(1,"rocketmq-demo-project-name");

    @PostMapping("/noArgs")
    public void noArgs(){
        producer.sendMessageWithValue(JSON.toJSONString(message));
    }

    @PostMapping("/withKey")
    public void withKey(){
        producer.sendMessageWithKey("chanchaw",JSON.toJSONString(message));
    }
    @PostMapping("/withTag")
    public void withTag(){
        producer.sendMessageWithTag("cc",JSON.toJSONString(message));
    }
    @PostMapping("/withAll")
    public void withAll(){
        producer.sendMessageWithAll("ccKey","cc",JSON.toJSONString(message));
    }
}
